
abstract class Shape {
    abstract getArea(): number; // 抽象方法
    abstract name: string // 抽象属性
    abstract get _name(): string // 抽象 访问器
    abstract set _name(value: string)// 抽象设置器
}

class Rectangle extends Shape {
    get _name(): string {
        throw new Error("Method not implemented.")
    }
    name: string = 'rectangle'
    constructor(
        public width: number,
        public heigth: number
    ) {
        super()
    }

    getArea() {
        return this.width * this.heigth
    }
}

class Circle extends Shape {
    get _name(): string {
        throw new Error("Method not implemented.")
    }
    set _name(value: string) {
        throw new Error("Method not implemented.")
    }
    name: string = "circle"
    constructor(
        public r: number
    ) {
        super()
    }

    getArea() {
        return this.r ** 2 * Math.PI
    }
}



// 多态 父类引用 传入 子类 这就是 类的四大概念  继承 抽象 封装 多态
function getArea(shape: Shape) {
    return shape.getArea()
}



getArea(new Rectangle(10, 20))
getArea(new Circle(30))

console.log('getArea(new Rectangle(10, 20)): ', getArea(new Rectangle(10, 20)));
console.log('getArea(new Circle(30)): ', getArea(new Circle(30)));

export { }